<!-- 任务执行情况 -->
<template>
  <el-dialog title="摇号记录" :visible.sync="dialogVisible" @close="$emit('update:visible',false)"
             :close-on-click-modal="false">

    <div>
      <div class="search-list-table">
        <download :type="ranking" :option="downloadOption"></download>
      </div>
      <el-table
          ref="multipleTable"
          :data="arryList"
          tooltip-effect="dark"
          header-cell-class-name="table-text-c"
          height="400"
          cell-class-name="table-text-c">
        <el-table-column
            label="奖项"
            align="center">
          <template slot-scope="scope">
            {{prizeName}}
          </template>
        </el-table-column>
        <el-table-column
            label="摇中号"
            align="center"
        prop="code">
        </el-table-column>
        <el-table-column
            label="摇中者"
            align="center">
          <template slot-scope="scope">
            {{ scope.row.users?scope.row.users.realname:scope.row.student.name }}
          </template>
        </el-table-column>
      </el-table>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
            background
            :page-size="page.pagesize"
            :current-page="page.pageindex"
            layout="total, prev, pager, next"
            :total="page.total"
            @current-change="handleSizeChange"></el-pagination>
      </el-col>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="$emit('update:visible',false)" size="small">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import {pagination} from '@/utils/util.js'
import download from '@/components/common/download'

export default {
  name: 'taskListDialog',
  props: ['visible', 'drawId', 'prizeId', 'prizeName'],
  components: {
    download
  },
  data() {
    return {
      dialogVisible: this.visible,
      arryList: [],
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      name: '',
      addtime: [],
      ranking: 'giftUser',
      downloadOption: {
        draw_id: this.drawId,
        prize_id: this.prizeId
      }
    }
  },
  created() {
  },
  methods: {
    InitFn() {
      this.$fetch(this.api.giftDraw.prizeCode, {
        p: 1,
        draw_id: this.drawId,
        prize_id: this.prizeId
      }).then((response) => {
        for(let i in response.list.data){
          response.list.data[i].code = Number(response.list.data[i].code) < 10 ? ('0' + Number(response.list.data[i].code)) + '号' : response.list.data[i].code + '号'
        }
        this.arryList = response.list.data
        this.page.total = response.list.total
      }).catch((err) => {
        console.log(err)
      })
    },
    foodCheck() {

    },
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.downloadOption.draw_id = this.drawId
        this.downloadOption.prize_id = this.prizeId
        this.InitFn()
      } else {
        this.page.pageindex = 1
        this.arryList = []
      }
    }
  },
  mounted() {

  }
}
</script>
